import {LogLanguage} from "../dist/index.js"

// 最终测试用例
const testCases = [
  // 字符串测试
  'INFO User "john_doe" logged in',
  'ERROR Database "main_db" connection failed',
  'DEBUG Processing request `{"id": 123}`',
  'WARN Invalid input \'user@example.com\'',
  
  // 数值测试
  'INFO Response time=0.123s',
  'ERROR Error code: 404',
  'DEBUG Batch size: 1000',
  'INFO Temperature: 25.6°C',
  
  // 类路径测试
  'INFO [service.AuthService] User authenticated',
  'ERROR (com.example.MyClass:123) Exception occurred',
  'DEBUG [router/router.go:12] Request processed',
  
  // 事务ID测试
  'INFO [TID:abc123] Request processed',
  'ERROR [TID:fcdfba1a21214a8e97c7d8fd1a8aa287.1161.17544505317727189] Service failed',
  
  // 复杂日志行
  '2024-01-15T10:30:45.123+0800 INFO [TID:abc123] [service.AuthService] User "admin" logged in with session_id="sess_456" after 0.25s'
]

console.log("🎉 Final testing of LogLanguage parser with all features...")

let totalTests = 0
let passedTests = 0

testCases.forEach((testCase, index) => {
  console.log(`\n📝 Test case ${index + 1}:`)
  console.log(`Input: ${testCase}`)
  totalTests++
  
  try {
    const tree = LogLanguage.parser.parse(testCase)
    console.log("✅ Parse successful!")
    
    // 检查所有节点
    let foundElements = {
      FATALExpression: [],
      ERRORExpression: [],
      INFOExpression: [],
      WARNINGExpression: [],
      DebugExpression: [],
      DATEExpression: [],
      CLASSPATHExpression: [],
      TIDExpression: [],
      StringLiteral: [],
      NumberExpression: []
    }
    
    tree.iterate({
      enter: (node) => {
        const text = testCase.slice(node.from, node.to)
        if (foundElements.hasOwnProperty(node.name)) {
          foundElements[node.name].push(text)
        }
      }
    })
    
    // 输出结果
    let hasElements = false
    Object.entries(foundElements).forEach(([name, elements]) => {
      if (elements.length > 0) {
        console.log(`✅ Found ${elements.length} ${name}: ${elements.join(', ')}`)
        hasElements = true
      }
    })
    
    if (hasElements) {
      passedTests++
      console.log("🎯 Test PASSED!")
    } else {
      console.log("⚠️  No special elements found (but parse successful)")
    }
    
  } catch (error) {
    console.log(`❌ Parse failed: ${error.message}`)
  }
})

console.log(`\n📊 Test Results: ${passedTests}/${totalTests} tests passed`)
console.log("🎉 String and Number recognition is now working!") 